// DlgInformation.cpp : implementation file
//

#include "stdafx.h"
#include "Celsus.h"
#include "DlgInformation.h"


// CDlgInformation dialog

IMPLEMENT_DYNAMIC(CDlgInformation, CDialog)

CDlgInformation::CDlgInformation(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgInformation::IDD, pParent)
{

}

CDlgInformation::~CDlgInformation()
{
}

void CDlgInformation::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EXPLORER, m_ctrlBrowser);
}


BEGIN_MESSAGE_MAP(CDlgInformation, CDialog)
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_BUTTON_BACK, &CDlgInformation::OnBnClickedButtonBack)
	ON_BN_CLICKED(IDC_BUTTON_FORWARD, &CDlgInformation::OnBnClickedButtonForward)
END_MESSAGE_MAP()

BEGIN_EVENTSINK_MAP(CDlgInformation, CDialog)
	ON_EVENT(CDlgInformation, IDC_EXPLORER, 105, CDlgInformation::CommandStateChangeExplorer, VTS_I4 VTS_BOOL)
END_EVENTSINK_MAP()


// CDlgInformation message handlers

BOOL CDlgInformation::OnInitDialog()
{
	CDialog::OnInitDialog();

	// navigate to information
	m_ctrlBrowser.Navigate( m_szURL, NULL, NULL, NULL, NULL );

	// size the dialog
	SizeDialog();

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgInformation::OnSize(UINT nType, int cx, int cy)
{
	CDialog::OnSize(nType, cx, cy);

	// size the dialog
	SizeDialog();
}

void CDlgInformation::CommandStateChangeExplorer(long Command, BOOL Enable)
{
	switch( Command )
	{
		// Forward command
		case CSC_NAVIGATEFORWARD:
			GetDlgItem( IDC_BUTTON_FORWARD )->EnableWindow( Enable );
			break;

		// Back command
		case CSC_NAVIGATEBACK:
			GetDlgItem( IDC_BUTTON_BACK )->EnableWindow( Enable );
			break;

		default:
			break;
	}
}

void CDlgInformation::OnBnClickedButtonBack()
{
	// go back
	m_ctrlBrowser.GoBack();
}

void CDlgInformation::OnBnClickedButtonForward()
{
	// go forward
	m_ctrlBrowser.GoForward();
}

BOOL CDlgInformation::SizeDialog(void)
{
	if( !m_ctrlBrowser )
		return FALSE;

	CWnd *pWindow;
	CRect rectDlg;
	CRect rectCtl;

	GetWindowRect( rectDlg );
	INT nWidth = rectDlg.Width();
	INT nHeight = rectDlg.Height();

	// IDC_EXPLORER
	m_ctrlBrowser.GetWindowRect( rectCtl );
	ScreenToClient( rectCtl );
	m_ctrlBrowser.MoveWindow( rectCtl.left, rectCtl.top, rectDlg.Width() - 30, rectDlg.Height() - 100, FALSE );

	// IDCANCEL
	pWindow = GetDlgItem( IDCANCEL );
	pWindow->GetWindowRect( rectCtl );
	ScreenToClient( rectCtl );
	pWindow->MoveWindow( rectDlg.Width() - 100, rectDlg.Height() - 70, rectCtl.Width(), rectCtl.Height(), FALSE );

	// IDC_BUTTON_BACK
	pWindow = GetDlgItem( IDC_BUTTON_BACK );
	pWindow->GetWindowRect( rectCtl );
	ScreenToClient( rectCtl );
	pWindow->MoveWindow( rectCtl.left, rectDlg.Height() - 70, rectCtl.Width(), rectCtl.Height(), FALSE );

	// IDC_BUTTON_FORWARD
	pWindow = GetDlgItem( IDC_BUTTON_FORWARD );
	pWindow->GetWindowRect( rectCtl );
	ScreenToClient( rectCtl );
	pWindow->MoveWindow( rectCtl.left, rectDlg.Height() - 70, rectCtl.Width(), rectCtl.Height(), FALSE );

	// redraw window
	RedrawWindow();

	return TRUE;
}
